﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using H2.NET.Controls;
using H2.NET.Business;
using H2.NET.Data.Common;

using System.IO;
using H2.NET.Data.Exceller;

 

namespace H2.NET.Web.Pages 
{
    public partial class PATR : TaskPage
    {
        #region 属性 Public
        private bool IsLoaded
        {
            get
            {
                return ViewState["IsLoaded"] == null ? false : (bool)ViewState["IsLoaded"];
            }
            set { ViewState["IsLoaded"] = value; }
        }
        #endregion
        protected string userlink;
        #region 事件 Page_Load(页面加载)
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                IList<t_BPM_CN116_mLink> uLst = (t_BPM_CN116_mLink._Status == 1 & t_BPM_CN116_mLink._BU == UserAPI.Department).List<t_BPM_CN116_mLink>();
                lLink.Visible = uLst.Count > 0;
                userlink = uLst.Count > 0 ? uLst[0].LINK : "";
                INFO.Text = string.Format("<br/>表单正在被同事“{0}”抢占处理，拒绝提交！", RobUser);
                INFO.Visible = IsOverFlow;
                if (!TaskAPI.IsAllowSubmit) Assessment1.Visible = false;
                //InitDropDownList();
                bool flg = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;
                
                #region 发起步骤
                if ((TaskAPI.IsBeginStep&& TaskAPI.IsAllowSubmit))
                {
                    InitDropDownList();
                    SetColor();
                }              
                #endregion

                #region 审批环节
                if (!TaskAPI.IsInitiate)
                {
                    #region 加载数据并显示
                    t_BPM_CN116 st = (t_BPM_CN116.process == TaskAPI.Process & t_BPM_CN116.incident == TaskAPI.Incident).ListFirst<t_BPM_CN116>();
                    if (st != null)
                    {
                        SetDropDownListValue(Actions, st.Actions);
                        SetColor();
                        ApplicationNo.Text                  = st.ApplicationNo;
                        Actions.SelectedValue               = st.Actions;
                        Date.Text = st.Time.ToString();
                        Applicator.Text = st.UserFullName;
                        SetDropDownListValue(PT_BU, st.PT_BU);
                        
                        SetDropDownListValue(PT_SBU, st.PT_SBU);

                        SetDropDownListValue(PT_Department, st.PT_Department);
                        SetDropDownListValue(PT_Section, st.PT_Section);
                        
                        PT_Job_Title.Text = st.PT_Job_Title;
                        PT_Job_Level.Text = st.PT_Job_Level;

                        SetDropDownListValue(PT_Contract_Type, st.PT_Contract_Type);


                        SetDropDownListValue(PT_Reason_For_Hiring, st.PT_Reason_For_Hiring);


                        PT_Legal_Entity.Text = st.PT_Legal_Entity;
                        PT_Location.Text = st.PT_Location;
                        PT_Replacement_For.Text = st.PT_Replacement_For;
                        PT_Resigned.Checked = st.PT_Resigned == "1";
                        PT_Terminated.Checked = st.PT_Terminated == "1";
                        PT_Transferred.Checked = st.PT_Transferred == "1";
                        PT_Promoted.Checked = st.PT_Promoted == "1";
                        PT_Report_Department.Text = st.PT_Report_Department;
                        PT_Starting_Salary.Text = st.PT_Starting_Salary;
                        PT_Expected_Date.Text = st.PT_Expected_Date;
                        SetDropDownListValue(PT_Agreement, st.PT_Agreement);
                        SetDropDownListValue(PT_Process, st.PT_Process);
                        SetDropDownListValue(PT_This_Year, st.PT_This_Year);


                        this.UsersChoose1.USR_Inform_Recruiter_C.Checked = false;
                        this.UsersChoose1.USR_5th_Approver_C.Checked = false;
                        this.UsersChoose1.USR_4th_Approver_C.Checked = false;
                        this.UsersChoose1.USR_3rd_Approver_C.Checked = false;
                        this.UsersChoose1.USR_Final_Approver_C.Checked = false;


                        if (TaskAPI["R_Inform_Recruiter"] != null)
                        {
                            object[] obj1 = (object[])(TaskAPI["R_Inform_Recruiter"]);
                            for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                            {
                                if (!string.IsNullOrEmpty(obj1[i].ToString()))
                                {
                                    string SQL = "select rtrim(NAME) as username, rtrim(FULLNAME) AS fullname from jobs where rtrim(name)='" + obj1[i].ToString() + "'";
                                    TaskDB.Log("", true, "UserChoose - USR_TextChanged:" + SQL);

                                    DBAPI.Storage("bpmDB1");
                                    DataTable dt = DBAPI.Query(SQL);

                                    //根据查询结果进行赋值
                                    if (dt.Rows.Count > 0)
                                    {
                                        this.UsersChoose1.USR_Inform_Recruiter.Text = dt.Rows[0]["FULLNAME"].ToString();
                                        this.UsersChoose1.USR_Inform_Recruiter_C.Checked = true;
                                    }
 
                                }
                            }
                        }
                        if (TaskAPI["Seventh_Manager"] != null)
                        {
                            object[] obj1 = (object[])(TaskAPI["Seventh_Manager"]);
                            for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                            {
                                if (!string.IsNullOrEmpty(obj1[i].ToString()))
                                {
                                    string SQL = "select rtrim(NAME) as username, rtrim(FULLNAME) AS fullname from jobs where rtrim(name)='" + obj1[i].ToString() + "'";
                                    TaskDB.Log("", true, "UserChoose - USR_TextChanged:" + SQL);

                                    DBAPI.Storage("bpmDB1");
                                    DataTable dt = DBAPI.Query(SQL);

                                    //根据查询结果进行赋值
                                    if (dt.Rows.Count > 0)
                                    {
                                        this.UsersChoose1.USR_7th_Approver.Text = dt.Rows[0]["FULLNAME"].ToString();

                                    }

                                }
                            }
                        }

                        if (TaskAPI["Sixth_Manager"] != null)
                        {
                            object[] obj1 = (object[])(TaskAPI["Sixth_Manager"]);
                            for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                            {
                                if (!string.IsNullOrEmpty(obj1[i].ToString()))
                                {
                                    string SQL = "select rtrim(NAME) as username, rtrim(FULLNAME) AS fullname from jobs where rtrim(name)='" + obj1[i].ToString() + "'";
                                    TaskDB.Log("", true, "UserChoose - USR_TextChanged:" + SQL);

                                    DBAPI.Storage("bpmDB1");
                                    DataTable dt = DBAPI.Query(SQL);

                                    //根据查询结果进行赋值
                                    if (dt.Rows.Count > 0)
                                    {
                                        this.UsersChoose1.USR_6th_Approver.Text = dt.Rows[0]["FULLNAME"].ToString();

                                    }

                                }
                            }
                        }
                        if (TaskAPI["Fifth_Manager"] != null)
                        {
                            object[] obj1 = (object[])(TaskAPI["Fifth_Manager"]);
                            for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                            {
                                if (!string.IsNullOrEmpty(obj1[i].ToString()))
                                {
                                    string SQL = "select rtrim(NAME) as username, rtrim(FULLNAME) AS fullname from jobs where rtrim(name)='" + obj1[i].ToString() + "'";
                                    TaskDB.Log("", true, "UserChoose - USR_TextChanged:" + SQL);

                                    DBAPI.Storage("bpmDB1");
                                    DataTable dt = DBAPI.Query(SQL);

                                    //根据查询结果进行赋值
                                    if (dt.Rows.Count > 0)
                                    {
                                        this.UsersChoose1.USR_5th_Approver.Text = dt.Rows[0]["FULLNAME"].ToString();
                                        this.UsersChoose1.USR_5th_Approver_C.Checked = true;
                                    }
 
                                }   
                            }
                        }
                        if (TaskAPI["Fouth_Manager"] != null)
                        {
                            object[] obj1 = (object[])(TaskAPI["Fouth_Manager"]);
                            for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                            {
                                if (!string.IsNullOrEmpty(obj1[i].ToString()))
                                {
                                    string SQL = "select rtrim(NAME) as username, rtrim(FULLNAME) AS fullname from jobs where rtrim(name)='" + obj1[i].ToString() + "'";
                                    TaskDB.Log("", true, "UserChoose - USR_TextChanged:" + SQL);

                                    DBAPI.Storage("bpmDB1");
                                    DataTable dt = DBAPI.Query(SQL);

                                    //根据查询结果进行赋值
                                    if (dt.Rows.Count > 0)
                                    {
                                        this.UsersChoose1.USR_4th_Approver.Text = dt.Rows[0]["FULLNAME"].ToString();
                                        this.UsersChoose1.USR_4th_Approver_C.Checked = true;
                                    }
 
                                }
                            }
                        }
                        if (TaskAPI["Third_Manager"] != null)
                        {
                            object[] obj1 = (object[])(TaskAPI["Third_Manager"]);
                            for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                            {
                                if (!string.IsNullOrEmpty(obj1[i].ToString()))
                                {
                                    string SQL = "select rtrim(NAME) as username, rtrim(FULLNAME) AS fullname from jobs where rtrim(name)='" + obj1[i].ToString() + "'";
                                    TaskDB.Log("", true, "UserChoose - USR_TextChanged:" + SQL);

                                    DBAPI.Storage("bpmDB1");
                                    DataTable dt = DBAPI.Query(SQL);

                                    //根据查询结果进行赋值
                                    if (dt.Rows.Count > 0)
                                    {
                                        this.UsersChoose1.USR_3rd_Approver.Text = dt.Rows[0]["FULLNAME"].ToString();
                                        this.UsersChoose1.USR_3rd_Approver_C.Checked = true;
                                    }
 
                                }
                            }
                        }
                        if (TaskAPI["Final_Approver"] != null)
                        {
                            object[] obj1 = (object[])(TaskAPI["Final_Approver"]);
                            for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                            {
                                if (!string.IsNullOrEmpty(obj1[i].ToString()))
                                {
                                    string SQL = "select rtrim(NAME) as username, rtrim(FULLNAME) AS fullname from jobs where rtrim(name)='" + obj1[i].ToString() + "'";
                                    TaskDB.Log("", true, "UserChoose - USR_TextChanged:" + SQL);

                                    DBAPI.Storage("bpmDB1");
                                    DataTable dt = DBAPI.Query(SQL);

                                    //根据查询结果进行赋值
                                    if (dt.Rows.Count > 0)
                                    {
                                        this.UsersChoose1.USR_Final_Approver.Text = dt.Rows[0]["FULLNAME"].ToString();
                                        this.UsersChoose1.USR_Final_Approver_C.Checked = true;
                                    }
 
                                }
                            }
                        }
                        if (TaskAPI["Approver"] != null)
                        {
                            object[] obj1 = (object[])(TaskAPI["Approver"]);
                            for (int i = 0; i <= obj1.GetUpperBound(0); i++)
                            {
                                if (!string.IsNullOrEmpty(obj1[i].ToString()))
                                {
                                    string SQL = "select rtrim(NAME) as username, rtrim(FULLNAME) AS fullname from jobs where rtrim(name)='" + obj1[i].ToString() + "'";
                                    TaskDB.Log("", true, "UserChoose - USR_TextChanged:" + SQL);

                                    DBAPI.Storage("bpmDB1");
                                    DataTable dt = DBAPI.Query(SQL);

                                    //根据查询结果进行赋值
                                    if (dt.Rows.Count > 0)
                                    {
                                        this.UsersChoose1.USR_Approver.Text = dt.Rows[0]["FULLNAME"].ToString();
                                        this.UsersChoose1.USR_Approver_C.Checked = true;
                                    }
 
                                }
                            }
                        }
                      
                    }
                    #endregion

                    #region 审批项初始化
                    switch(TaskAPI.Step)
                    {
                        case "1st Manager":
                        case "2nd Manager":
                        case "3rd Manager":
                        case "4th Manager":
                        case "5th Manager":
                        case "6th Manager":
                        case "7th Manager":
                            Assessment1.Option.Add(new t_AssessmentOption("Approve", "1", true));
                            Assessment1.Option.Add(new t_AssessmentOption("Reject", "3", false));
                            Assessment1.Option.Add(new t_AssessmentOption("More Info.", "2", false));
                            break;
                    }
                    #endregion
                }
                #endregion

                SetDefaultValue();

                #region 设置控件禁启用
                //bool flg = (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) ? true : false;
                SetEnable(flg, PT_BU, PT_SBU, PT_Department, PT_Section, PT_Job_Title, PT_Job_Level, PT_Contract_Type, PT_Legal_Entity, PT_Reason_For_Hiring, PT_Location,PT_Replacement_For, PT_Resigned, PT_Terminated, PT_Transferred, PT_Promoted, PT_Report_Department, PT_Starting_Salary, PT_Expected_Date, PT_Agreement, PT_Process, PT_This_Year);
                //SetVisible(flg, Add, Delete);
                //SetVisible(flg, Add, Delete);
                SetVisible(TaskAPI.IsAllowSubmit, Send, Split);

                Attachment1.AllowDelete = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                Attachment1.AllowUpload = TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit;
                SetVisible(PT_Reason_For_Hiring.Text == "replacement", P4);
                #endregion

                #region 颜色加深
                if (!flg || !TaskAPI.IsAllowSubmit)
                {
                    foreach (Control cr in P1.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }
                    foreach (Control cr in P1.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                    foreach (Control cr in P4.Controls)
                    {
                        if (cr is TextBox)
                        {
                            TextBox tb = (TextBox)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ReadOnly = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }
                    foreach (Control cr in P4.Controls)
                    {
                        if (cr is DropDownList)
                        {
                            DropDownList tb = (DropDownList)cr;
                            if (!tb.Enabled)
                            {
                                tb.Enabled = true;
                                tb.ForeColor = System.Drawing.Color.DimGray;
                            }
                        }
                    }

                    this.Actions.Enabled = true;
                }
                #endregion
            }
        }
        #endregion

        #region 事件 Send
        protected void Send_Click(object sender, EventArgs e)
        {
            try
            {
                #region 数据验证
                List<Regular> regs = new List<Regular>();
                if (TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) // 如果是退回的情况，不存在验证
                {

                   
                    List<string> vald_s = new List<string>();
                    vald_s.AddRange(DataValidation());
                    vald_s.AddRange(UsersChoose1.DataValidation());

                    switch (TaskAPI.Step)
                    {
                        case "1st Manager":
                        case "2nd Manager":
                        case "3rd Manager":
                        case "4th Manager":
                        case "5th Manager":
                        case "6th Manager":
                        case "7th Manager":

                            if (Assessment1.Assessment.Opinion == "2")
                            {
                                regs.Add(new Regular(RegularExp.NotEmpty, Assessment1.Assessment.Remark, "Opinion; 请在Remark中写入退回理由"));
                            }
                            else if (Assessment1.Assessment.Opinion == "3")
                            {
                                regs.Add(new Regular(RegularExp.NotEmpty, Assessment1.Assessment.Remark, "Opinion; 请在Remark中写入 拒绝理由"));
                            }
                            break;

                    }
                    
                    if (vald_s.Count > 0)
                    {
                        Anthem.Manager.AddScriptForClientSideEval(string.Format("ShowMessage(\"{0}\", {1});", CombineMessage(vald_s), vald_s.Count));
                        return;
                    }

                   
                    
                }
                #endregion

                #region 引擎传值
                if (TaskAPI.IsBeginStep)
                {
                    if (TaskAPI.IsInitiate)
                    {
                        ApplicationNo.Text        = Util.GenerateSequence(((object[])TaskAPI["PrefixNo"])[0].ToString() + "-" + System.DateTime.Now.ToString("yyMM"), "", 4);
                        TaskAPI.UserName          = UserAPI.UserName;
                        TaskAPI["ApplicationNo"]  = ApplicationNo.Text;
                        TaskAPI["ApplicatorName"] = UserAPI.UserFullName;
                        TaskAPI["Applicator"]     = UserAPI.UserName;
                        TaskAPI["Time"]           = System.DateTime.Now.ToString("yyyy.MM.dd HH:mm:ss");
                        TaskAPI["ApplicatorEmail"] = UserAPI.Mail;
                        TaskAPI["Department"]     = UserAPI.Department;
                    }

                    TaskAPI.Summary = (Actions.SelectedItem.Text.Split(',').Length >= 2 ? Actions.SelectedItem.Text.Split(',')[1].Trim() : Actions.Text) + " / " + ApplicationNo.Text;
                    
                    TaskAPI["Actions"]        = Actions.SelectedValue;
                    TaskAPI["Remark_by_Initiator"] = Assessment1.Assessment.Remark;

                    #region 从数据库取得流程步骤处理人
                    #endregion 
                }
                else
                {
                    TaskAPI["ApproveResult"] = Assessment1.Assessment.Opinion;
                    TaskAPI["TaskID"]        = TaskAPI.TaskID;
                }

                //if (TaskAPI.IsBeginStep && !TaskAPI.IsInitiate
                //&& (Action_Type != Actions.SelectedValue || account_Type != VD_account_Type.SelectedValue))
                //{
                //    string PreStep = ((object[])TaskAPI["PreStep"])[0].ToString();
                //    if (PreStep.Trim() != "" && PreStep.Trim() != "Manager Approve")
                //    {
                //        TaskAPI["PreStep"] = "DMO Approve";
                //    }
                //}

                //#region 退回步骤并返回功能 传值
                //if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                //{
                //    TaskAPI["Step"] = Assessment1.JumpStep;
                //    TaskAPI["PreStep"] = TaskAPI.Step;
                //}
                //else
                //{
                //    string PreStep = ((object[])TaskAPI["PreStep"])[0].ToString();
                //    if (PreStep.Trim() != "")
                //    {
                //        TaskAPI["Step"]    = PreStep;
                //        TaskAPI["PreStep"] = "";
                //    }
                //    else
                //    {
                //        TaskAPI["Step"] = "";
                //        TaskAPI["PreStep"] = "";
                //    }
                //}
                //#endregion

                #endregion

                #region 提交步骤
                bool flg=false;
                Storage.TransactionExecute(o =>
                {
                    #region “Fill in the form”步骤
                    if (TaskAPI.IsBeginStep)
                    {
                        t_BPM_CN116 st = new t_BPM_CN116();
                        if ((t_BPM_CN116.process == TaskAPI.Process & t_BPM_CN116.incident == TaskAPI.Incident & t_BPM_CN116.userName == UserAPI.UserName).Count<t_BPM_CN116>() > 0)
                        {
                            st = (t_BPM_CN116.process == TaskAPI.Process & t_BPM_CN116.incident == TaskAPI.Incident & t_BPM_CN116.userName == UserAPI.UserName).ListFirst<t_BPM_CN116>();
                        }
                        else
                        {
                            st.Process       = TaskAPI.Process;
                            st.Incident      = TaskAPI.Incident;
                            st.UserName      = UserAPI.UserName;
                            st.UserFullName  = UserAPI.UserFullName;
                            st.ApplicationNo = ApplicationNo.Text;
                            st.Time          = System.DateTime.Now;
                            st.Status        = 0;
                            st.Department    = UserAPI.Department;
                        }

                        st.Actions           = Actions.SelectedValue;
                        st.Actions           = Actions.SelectedItem.Text;

                        st.Actions           = Actions.SelectedValue;
                        st.PT_BU = PT_BU.SelectedValue;
                        st.PT_SBU = PT_SBU.SelectedValue;
                        st.PT_Department = PT_Department.SelectedValue;
                        st.PT_Section = PT_Section.SelectedValue;
                        st.PT_Job_Title = PT_Job_Title.Text;
                        st.PT_Job_Level = PT_Job_Level.Text;
                        st.PT_Contract_Type = PT_Contract_Type.SelectedValue;
                        st.PT_Legal_Entity = PT_Legal_Entity.Text;
                        st.PT_Location = PT_Location.Text;
                        st.PT_Reason_For_Hiring = PT_Reason_For_Hiring.SelectedValue;
                        st.PT_Replacement_For = PT_Replacement_For.Text;
                        st.PT_Resigned = PT_Resigned.Checked ? "1" : "0";
                        st.PT_Terminated = PT_Terminated.Checked ? "1" : "0";
                        st.PT_Transferred = PT_Transferred.Checked ? "1" : "0";
                        st.PT_Promoted = PT_Promoted.Checked ? "1" : "0";
                        st.PT_Report_Department = PT_Report_Department.Text;
                        st.PT_Starting_Salary = PT_Starting_Salary.Text;
                        st.PT_Expected_Date = PT_Expected_Date.Text;
                        st.PT_Agreement = PT_Agreement.SelectedValue;
                        st.PT_Process = PT_Process.SelectedValue;
                        st.PT_This_Year = PT_This_Year.SelectedValue;

                        st.First_Approver = this.UsersChoose1.USR_Approver.Text;
                        st.Final_Approver = this.UsersChoose1.USR_Final_Approver.Text;
                        st.Third_Approver = this.UsersChoose1.USR_3rd_Approver.Text;
                        st.Fourth_Approver = this.UsersChoose1.USR_4th_Approver.Text;
                        st.Fifth_Approver = this.UsersChoose1.USR_5th_Approver.Text;
                        st.Sixth_Approver = this.UsersChoose1.USR_6th_Approver.Text;
                        st.Seventh_Approver = this.UsersChoose1.USR_7th_Approver.Text;
                        st.Inform_Recruiter = this.UsersChoose1.USR_Inform_Recruiter.Text;

                        (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                        {
                            p.Incident = TaskAPI.Incident;
                        });

                        Storage.Save(Storage.Context1, st);
                    }
                    #endregion

                    //#region “DMO Maintain”步骤
                    //if (TaskAPI.Step == "DMO Maintain")
                    //{
                    //    (gla_GLAccount.process == TaskAPI.Process & gla_GLAccount.incident == TaskAPI.Incident).Edit<gla_GLAccount>(p =>
                    //    {
                    //        p.SAP_Code = SAP_Code.Text;
                    //    }    
                    //    );
                    //}
                    //#endregion

                    Storage.Save(Assessment1.Assessment);    //审批意见

                    //多节点退回
                    if (!string.IsNullOrEmpty(Assessment1.JumpStep))
                    {
                        Assessment1.SetAsReturn(true);
                        TaskAPI.DirectActive(Assessment1.JumpStep);
                    }
                    else
                    {
                        Assessment1.SetAsReturn(false);
                    }
                    Assessment1.SubmitTo();

                    flg = TaskAPI.Send();
                });

                //如果数据库写入成功且流程发起成功的情况，将业务表数据与流程实例号进行关联
                if (TaskAPI.IsInitiate)
                {
                    (t_BPM_CN116.process == TaskAPI.Process & t_BPM_CN116.incident == 0 & t_BPM_CN116.userName == UserAPI.UserName).Edit<t_BPM_CN116>(p => 
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Assessment.process == TaskAPI.Process & t_Assessment.incident == 0 & t_Assessment.assignedToUserName == UserAPI.UserName).Edit<t_Assessment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                    (t_Attachment.process == TaskAPI.Process & t_Attachment.incident == 0 & t_Attachment.username == UserAPI.UserName).Edit<t_Attachment>(p =>
                    {
                        p.Incident = TaskAPI.Incident;
                    });

                }
                #endregion

                Send.Visible = false;
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Success + "',true)");
            }
            catch (Exception ex)
            {
                TaskDB.Log("", false, "调用NVA方法Send_Click出错：" + ex.ToString());
                Anthem.Manager.AddScriptForClientSideEval("JSInfomation('" + Resources.Global.C_00_Failed + "',false)");
            }
        }
        #endregion

        #region 事件 Actions 变换
        protected void Actions_SelectedIndexChanged(object sender, EventArgs e)
        {
            SetColor();
            SetEnable((Actions.SelectedValue == "1"), PT_BU, PT_SBU, PT_Department, PT_Section, PT_Job_Title, PT_Job_Level, PT_Contract_Type, PT_Legal_Entity, PT_Reason_For_Hiring, PT_Replacement_For, PT_Resigned, PT_Terminated, PT_Transferred, PT_Promoted, PT_Report_Department, PT_Starting_Salary, PT_Expected_Date, PT_Agreement, PT_Process, PT_This_Year);
        }
        #endregion

        #region 方法 SetColor
        protected void SetColor()
        {
            SetForeColor(Color.Blue, PT_BU_L, PT_SBU_L, PT_Department_L, PT_Section_L, PT_Section_L, PT_Job_Title_L, PT_Job_Level_L, PT_Contract_Type_L, PT_Legal_Entity_L, PT_Legal_Entity_L, PT_Location_L, PT_Reason_For_Hiring_L, PT_Agreement_L, PT_This_Year_L, PT_Agreement_L, PT_Replacement_For_L, PT_Process_L);

        }
        #endregion

        #region 方法 SetDefaultValue(设置默认值, 并禁用输入)
        public void SetDefaultValue()
        {
         
        }
        #endregion
    
        #region 方法 InitDropdownList
        private void InitDropDownList()
        {
            if (!IsLoaded)
            {
                #region Contract Type
                PT_Contract_Type.Items.Clear();
                PT_Contract_Type.Items.Add(new ListItem("", ""));
                IList<t_BPM_CN116_mContractType> sa1 = (t_BPM_CN116_mContractType.status == 1).List<t_BPM_CN116_mContractType>();
                foreach (t_BPM_CN116_mContractType SA in sa1)
                {
                    PT_Contract_Type.Items.Add(new ListItem(SA.Contract_Type, SA.Contract_Type));
                }
                #endregion

                #region Reason for hiring
                PT_Reason_For_Hiring.Items.Clear();
                PT_Reason_For_Hiring.Items.Add(new ListItem("", ""));
                IList<t_BPM_CN116_mHiringReason> sb1 = (t_BPM_CN116_mHiringReason.status == 1).List<t_BPM_CN116_mHiringReason>();
                foreach (t_BPM_CN116_mHiringReason SB in sb1)
                {
                    PT_Reason_For_Hiring.Items.Add(new ListItem(SB.Hiring_Reason, SB.Hiring_Reason));
                }
                #endregion
                
                #region Bussiness Unit
                PT_BU.Items.Clear();
                PT_BU.Items.Add(new ListItem("", ""));
                IList<t_BPM_CN116_mBussinessUnit> sb2 = (t_BPM_CN116_mBussinessUnit.status == 1).List<t_BPM_CN116_mBussinessUnit>();
                foreach (t_BPM_CN116_mBussinessUnit SB in sb2)
                {
                    PT_BU.Items.Add(new ListItem(SB.Bussiness_Unit, SB.Bussiness_Unit));
                }
                #endregion

                IsLoaded = true;
            }
        }
        #endregion

        #region 方法 数据验证
        private List<string> DataValidation()
        {
            List<string> vald_s = new List<string>();
            List<Regular> regs = new List<Regular>();
            regs.Add(new Regular(RegularExp.NotEmpty, PT_BU.Text, "BU 必填"));
            regs.Add(new Regular(RegularExp.NotEmpty, PT_SBU.Text, "SBU 必填"));
            regs.Add(new Regular(RegularExp.NotEmpty, PT_Department.Text, "Department 必填"));
            regs.Add(new Regular(RegularExp.NotEmpty, PT_Section.Text, "Section 必填"));
            regs.Add(new Regular(RegularExp.NotEmpty, PT_Job_Title.Text, "Job Title/Position 必填"));

            regs.Add(new Regular(RegularExp.NotEmpty, PT_Job_Level.Text, "Job Level 必填"));
            regs.Add(new Regular(RegularExp.NotEmpty, PT_Contract_Type.SelectedValue, "Contract Type 必填"));
            regs.Add(new Regular(RegularExp.NotEmpty, PT_Legal_Entity.Text,"Legal Entity 必填"));

            regs.Add(new Regular(RegularExp.NotEmpty, PT_Location.Text, "Location 必填"));
            regs.Add(new Regular(RegularExp.NotEmpty, PT_Reason_For_Hiring.SelectedValue, "Reason for hiring 必填"));
            if (PT_Reason_For_Hiring.SelectedValue == "replacement")
            {
                regs.Add(new Regular(RegularExp.NotEmpty, PT_Replacement_For.Text,"Replacement for 必填"));
                if (!PT_Resigned.Checked && !PT_Terminated.Checked && !PT_Transferred.Checked && !PT_Promoted.Checked)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty, "", "Replacement for的类型 必须至少选一个"));
                }
                else if (PT_Promoted.Checked)
                {
                    regs.Add(new Regular(RegularExp.NotEmpty,PT_Report_Department.Text, "Dept. 必填"));
                }



            }


            regs.Add(new Regular(RegularExp.NotEmpty, PT_Agreement.SelectedValue, "ATR : This position needs to sign separate Confidential/Non-compete Agreement 必填"));
            regs.Add(new Regular(RegularExp.NotEmpty, PT_Process.SelectedValue, "ATR : E-RECRUITING PROCESS 必填"));
            regs.Add(new Regular(RegularExp.NotEmpty, PT_This_Year.SelectedValue, "ATR : This post is included in the agreed plan for this year 必填"));
            vald_s = Validation(regs);
            if (vald_s.Count > 0)
            {
                vald_s.Insert(0, "<font color='#0000FF'><b>ATR</b></font>");
            }
            //return Validation(regs);
            return vald_s;
        }
        #endregion

        #region 重载 OnLoadComplete
        protected override void OnLoadComplete(EventArgs e)
        {
            if (!IsLoaded && TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit)
            {
                Actions_SelectedIndexChanged(null, e);
            }

            base.OnLoadComplete(e);
        }
        #endregion      

        #region 方法 SetDropDownListValue
        private void SetDropDownListValue(Anthem.DropDownList drpT, object o)
        {
            try
            {
                if ((TaskAPI.IsBeginStep && TaskAPI.IsAllowSubmit) || drpT.Items.FindByValue(o.ToString()) != null)
                {
 
                    drpT.Items.Add(new ListItem(o.ToString(), o.ToString()));
                    drpT.SelectedValue = o.ToString();
                   
                    return;
                }

                drpT.Items.Add(new ListItem(o.ToString(), o.ToString()));
                drpT.SelectedIndex = 0;

            }
            catch (Exception)
            {
            }
        }
        #endregion

        #region replacment隐藏
        protected void PT_Reason_For_Hiring_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (PT_Reason_For_Hiring.SelectedValue == "replacement")
            {
                P4.Visible = true;
            }
            else
            {
                P4.Visible = false;
            }
        }
        #endregion

        #region BU连带下拉框
        
        protected void PT_BU_SelectedIndexChanged(object sender, EventArgs e)
        {

            PT_Section.Items.Clear();
            PT_Department.Items.Clear();
            PT_SBU.Items.Clear();
            PT_SBU.Items.Add(new ListItem("", ""));
            IList<t_BPM_CN116_mBussiness> brs = (t_BPM_CN116_mBussiness.status == 1 & (t_BPM_CN116_mBussiness.bU == PT_BU.SelectedValue
             | t_BPM_CN116_mBussiness.bU == "")).List<t_BPM_CN116_mBussiness>();
            foreach (t_BPM_CN116_mBussiness BR in brs)
            {
                if (PT_SBU.Items.FindByValue(BR.SBU) == null)
                {
                    PT_SBU.Items.Add(new ListItem(BR.SBU, BR.SBU));
                }

            }
        }

        protected void PT_SBU_SelectedIndexChanged(object sender, EventArgs e)
        {
            PT_Section.Items.Clear();
            PT_Department.Items.Clear();
            PT_Department.Items.Add(new ListItem("", ""));
            IList<t_BPM_CN116_mBussiness> bre = (t_BPM_CN116_mBussiness.bU == PT_BU.SelectedValue & t_BPM_CN116_mBussiness.status == 1 & (t_BPM_CN116_mBussiness.sBU == PT_SBU.SelectedValue
             | t_BPM_CN116_mBussiness.sBU == "")).List<t_BPM_CN116_mBussiness>();
            foreach (t_BPM_CN116_mBussiness BR in bre)
            {
                if (PT_Department.Items.FindByValue(BR.Department) == null)
                {
                    PT_Department.Items.Add(new ListItem(BR.Department, BR.Department));
                }

            }
        }

        protected void PT_Department_SelectedIndexChanged(object sender, EventArgs e)
        {
            PT_Section.Items.Clear();
            PT_Section.Items.Add(new ListItem("", ""));
            IList<t_BPM_CN116_mBussiness> brt =  (t_BPM_CN116_mBussiness.bU == PT_BU.SelectedValue  & t_BPM_CN116_mBussiness.sBU == PT_SBU.SelectedValue &(t_BPM_CN116_mBussiness.status == 1 & (t_BPM_CN116_mBussiness.department == PT_Department.SelectedValue
             | t_BPM_CN116_mBussiness.department == ""))).List<t_BPM_CN116_mBussiness>();
            foreach (t_BPM_CN116_mBussiness BR in brt)
            {
                if (PT_Section.Items.FindByValue(BR.SBU) == null)
                {
                    PT_Section.Items.Add(new ListItem(BR.Section, BR.Section));
                }

            }
        }
        
        #endregion



    }
}